package dao

import "morleyStoneHome/model"

type stoWithdrawDao struct {
}

var StoWithdrawDao = newStoWithdrawDao()

func newStoWithdrawDao() *stoWithdrawDao {
	return &stoWithdrawDao{}
}

//增单条
func (n *stoWithdrawDao) Insert(stoWithdraw *model.StoWithdraw) error {
	err := Db.Create(stoWithdraw).Error
	if nil != err {
		return err
	}
	return nil
}

////更新单条
//func (n *stoWithdrawDao) Update(addr string, stoWithdraw *model.StoWithdraw) error {
//	err := Db.Model(&model.StoWithdraw{}).Where("addr = ? ", addr).Updates(stoWithdraw).Error
//	if nil != err {
//		return err
//	}
//	return nil
//}
//
//根据addr查单条
func (n *stoWithdrawDao) FindList(addr string) (stoWithdraw []*model.StoWithdraw, err error) {
	res := Db.Where("addr = ? ", addr).Find(&stoWithdraw)
	if res.Error != nil {
		return nil, res.Error
	}
	return stoWithdraw, nil
}

//查询所有状态为1的提取记录：冻结中的交易
func (n *stoWithdrawDao) FindFreezeList() (stoWithdraw []*model.StoWithdraw, err error) {
	res := Db.Where("status = 1 ").Find(&stoWithdraw)
	if res.Error != nil {
		return nil, res.Error
	}
	return stoWithdraw, nil
}

//更新单条
func (n *stoWithdrawDao) UpdateByMap(uid int, m map[string]interface{}) error {
	err := Db.Model(&model.StoWithdraw{}).Where("uid = ? ", uid).Updates(m).Error
	if nil != err {
		return err
	}
	return nil
}
